import zipfile
import os


class Myzip:
    def __init__(self, file_path):
        self.file_path = file_path

    def unzip_file(self, destination=None):
        global azip
        message = ''
        status = 'failed'
        if os.path.exists(self.file_path):
            try:
                if destination and os.path.exists(destination):
                    azip = zipfile.ZipFile(self.file_path)
                    azip.extractall(destination)
                    message = '已解压至=>' + destination
                    status = 'success'
                else:
                    message = destination + " 路径不存在，解压到当前工作目录~"
                    azip = zipfile.ZipFile(self.file_path)
                    azip.extractall()
            except Exception as e:
                print(str(e))
            finally:
                azip.close()
        else:
            message = self.file_path + " 路径不存在！"
        return message, status


if __name__ == "__main__":
    myzip = Myzip('D:\edgeDownload\MyDockFinder win32&64 setup.zip')
    myzip.unzip_file('D:\Projects\PycharmProjects\insects_detection_flask_backend')
